package com.apes.crm.vip.vipInfo;

import com.apes.framework.api.DomainService;
import com.apes.framework.plugin.esb.api.SimpleRequest;
import com.apes.scm.masterdata.area.repository.AreaRepository;
import com.apes.scm.masterdata.party.repository.PartyRoleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 会员
 *
 * @author wuq
 * @create 2018-11-19 15:32
 */
@Service("crmVipInfoService")
public class VipInfoService extends DomainService {
    private static final String ROLE_TYPE = "Vip";

    @Autowired
    VipInfoRepository vipInfoRepository;

    @Autowired
    PartyRoleRepository partyRoleRepository;

    @Autowired
    AreaRepository areaRepository;

    public VipInfo save(SimpleRequest request){
        VipInfo vipInfo = request.getO(VipInfo.class);

        // 获取 居住.区县
        /*Area livingCounty = vipInfo.getLivingCounty();
        if(livingCounty!=null){
            // 获取 居住.城市编码
            String livingCityId = livingCounty.getParent();
            // 查找 居住.城市
            Area livingCity = areaRepository.findOne(livingCityId);
            // 设置 居住.城市
            vipInfo.setLivingCity(livingCity);
            String livingProvinceId = livingCity.getParent();
            // 设置 居住.省份
            Area livingProvince = areaRepository.findOne(livingProvinceId);
            vipInfo.setLivingProvince(livingProvince);
        }*/

        return vipInfoRepository.saveAndFlush(vipInfo);
    }

    public VipInfo update(SimpleRequest request){
        VipInfo vipInfo = request.getO(VipInfo.class);
        return vipInfoRepository.saveAndFlush(vipInfo);
    }
}
